/**
 * Cara place
 */
$('#cars_place ul').sortable({
    connectWith: "ul.exit, ul.cashier",
    receive: function(event, ui) {
        var id_brand = $(this).attr('in');
        var interest_in = ui.item.attr('in');
        var li_customer = ui.item;
        if (id_brand != interest_in) {
            $(".clients_queue").append(li_customer);
        } else {
            queue.count--;
        }
        IS_MOVING = true;
    }
});

/**
 * Exit
 */
$('.exit').sortable({
    receive: function( event, ui ) {
        IS_MOVING = true;
        setTimeout(function(){
            ui.item.remove();
            queue.count--;
        }, 1000);
    }
});

/**
 * Cashier
 */
$('.cashier').sortable();

/**
 * Arrival of customers
 */
$('.clients_queue').sortable({
    connectWith: "#cars_place ul, ul.exit",
    containment: '#salon',
    cursor: "move",
    revert: true,
    items: 'li.active',
    activate: function( event, ui ) {
        IS_MOVING = false;
    },     
    receive: function( event, ui ) {
        var id_brand = $(this).attr('in');
        var interest_in = ui.item.attr('in');
        var li_customer = ui.item;
         
        if (id_brand != interest_in) {
            $(".clients_queue").append(li_customer);
        } else {
            queue.count--;
        }
        IS_MOVING = true;
    },
    update: function (event, ui) {
        IS_MOVING = true;
    },
    change: function (event, ui) {
        IS_MOVING = true;
    }
}).disableSelection();